package com.d3works.apps.base.service;

import com.d3works.apps.base.db.ProductCategory;
import com.d3works.exception.D3worksException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

public interface ProductCategoryService {

  /**
   * Compute discount message from existing parent and child categories with a discount.
   *
   * @param productCategory a product category
   * @return a discount message describing discounts from other categories
   */
  String computeDiscountMessage(ProductCategory productCategory) throws D3worksException;

  /**
   * The maximum applicable discount for a product category is the max discount of the category or,
   * if this value is empty, the maximum applicable discount of its parent.
   *
   * @param productCategory
   * @return an optional with the maximum applicable discount if found.
   */
  Optional<BigDecimal> computeMaxDiscount(ProductCategory productCategory) throws D3worksException;

  /**
   * Find child of given category, and recursively children of found children.
   *
   * @param productCategory a product category
   * @return all children of the category
   */
  List<ProductCategory> fetchChildrenCategoryList(ProductCategory productCategory)
      throws D3worksException;

  /**
   * Find parent of given category, and recursively parents of found parents.
   *
   * @param productCategory a product category
   * @return all parents of the category
   */
  List<ProductCategory> fetchParentCategoryList(ProductCategory productCategory)
      throws D3worksException;

  /**
   * Get the growth coefficient of product category. If the coeff is equal to the default value (1),
   * the method will get growth coeff of parentProductCategory.
   *
   * @param productCategory
   * @return growth coefficient
   */
  BigDecimal getGrowthCoeff(ProductCategory productCategory);
}
